#### "Democracy and Development" ####
# authors: "Pelke, Lars"
# date: 2021-09-03
# written under "R version 34.1.1 (2021-08-10)"

#### Preliminaries ####

R.version$version.string

# clear workspace
rm(list=ls())

# set working directory
setwd("C:/Users/ba72loko/Promotion/Paper/Autocratization and Economic Well-Being/calculations_Nov_2021")


#### Preliminaries ####
library(tidyverse)
library(ggpubr)
library(haven)
library(viridis)
library(hrbrthemes)

#### Load Dataset ####

data_figure_2 <- read_dta("outputs/Step2/data_Figure.dta") 

#### Figure Step 2 ####

ggplot(data = data_figure_2, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#495e35", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(-15,40,5) ) +
  scale_x_continuous(breaks=seq(0,30,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") + 
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=16,face="bold"))

ggsave("outputs/Step2/Step2_Figure_4.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step2/Step2_Figure_4.eps", units= c("cm"), width = 40, height = 20,  dpi = 900)


#### Load Dataset. Additional Robustness test ####

data_figure2_robust <- read_dta("outputs/Step2/data_Figure_robust.dta") 

#### Figure Step 1 ####

ggplot(data = data_figure2_robust, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#440154FF", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(-20,50,5),  limits=c(-20,50)) +
  scale_x_continuous(breaks=seq(0,35,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") +
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=16,face="bold"))

ggsave("outputs/Step2/Step2_Figure_4_robust.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step2/Step2_Figure_4_robust.eps", units= c("cm"), width = 40, height = 20, dpi = 900)


